﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace Chizx.Web.companys
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
        {
            if (null == Session["UserEntity"])
            {
                Response.Redirect("/e/Login.aspx");
            }
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int zcom_id=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(zcom_id);
				}
			}
		}
			
	private void ShowInfo(int zcom_id)
	{
		Chizx.BLL.CompanysBll bll=new Chizx.BLL.CompanysBll();
		Chizx.Model.CompanysModel model=bll.GetModel(zcom_id);
		this.lblzcom_id.Text=model.zcom_id.ToString();
		this.txtzcom_name.Text=model.zcom_name;
		this.txtzcom_address.Text=model.zcom_address;
		this.txtzcom_desc.Text=model.zcom_desc;
		this.txtzcom_applynum.Text=model.zcom_applynum.ToString();
		this.txtzcom_passnum.Text=model.zcom_passnum.ToString();
		this.txtzcom_neednum.Text=model.zcom_neednum.ToString();
		this.txtzcom_createdate.Text=model.zcom_createdate.ToString();
        this.txtzcom_status.Text = model.zcom_status == "c0" ? "在招中" : (model.zcom_status == "c1" ? "已结束" : "未知状态");

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtzcom_name.Text.Trim().Length==0)
			{
				strErr+="zcom_name不能为空！\\n";	
			}
			if(this.txtzcom_address.Text.Trim().Length==0)
			{
				strErr+="zcom_address不能为空！\\n";	
			}
			if(this.txtzcom_desc.Text.Trim().Length==0)
			{
				strErr+="zcom_desc不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtzcom_applynum.Text))
			{
				strErr+="zcom_applynum格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtzcom_passnum.Text))
			{
				strErr+="zcom_passnum格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtzcom_neednum.Text))
			{
				strErr+="zcom_neednum格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txtzcom_createdate.Text))
			{
				strErr+="zcom_createdate格式错误！\\n";	
			}
			if(this.txtzcom_status.Text.Trim().Length==0)
			{
				strErr+="zcom_status不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int zcom_id=int.Parse(this.lblzcom_id.Text);
			string zcom_name=this.txtzcom_name.Text;
			string zcom_address=this.txtzcom_address.Text;
			string zcom_desc=this.txtzcom_desc.Text;
			int zcom_applynum=int.Parse(this.txtzcom_applynum.Text);
			int zcom_passnum=int.Parse(this.txtzcom_passnum.Text);
			int zcom_neednum=int.Parse(this.txtzcom_neednum.Text);
			DateTime zcom_createdate=DateTime.Parse(this.txtzcom_createdate.Text);
            string zcom_status = this.txtzcom_status.Text == "在招中" ? "c0" : (this.txtzcom_status.Text == "已结束" ? "c1" : "c2");


			Chizx.Model.CompanysModel model=new Chizx.Model.CompanysModel();
			model.zcom_id=zcom_id;
			model.zcom_name=zcom_name;
			model.zcom_address=zcom_address;
			model.zcom_desc=zcom_desc;
			model.zcom_applynum=zcom_applynum;
			model.zcom_passnum=zcom_passnum;
			model.zcom_neednum=zcom_neednum;
			model.zcom_createdate=zcom_createdate;
			model.zcom_status=zcom_status;

            //写入系统日志
            if (Session["UserEntity"] == null)
            {
                Response.Redirect("/e/Login.aspx");
            }
            else
            {
                Chizx.BLL.CompanysBll bll = new Chizx.BLL.CompanysBll();
                bll.Update(model);
                Chizx.Model.UserModel sbmmodel = (Chizx.Model.UserModel)Session["UserEntity"];
                Chizx.BLL.SystemLogBll sbll = new Chizx.BLL.SystemLogBll();
                Chizx.Model.SystemLogModel slm = new Chizx.Model.SystemLogModel();
                slm.zu_id = sbmmodel.zu_id;
                slm.zl_dowhen = DateTime.Now;
                slm.zl_dowhat = "修改招聘单位信息";
                slm.zl_dotype = "3";//0:Test,1:Auth,2:Read,3:Write,4:Del,5:Inpor
                slm.zl_dodesc = "操作成功";
                sbll.Add(slm);
                Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");
            }

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
